<template>
  <div class="shopcar-container">
    <div class="mui-card goods-list" v-for="item in goodslist" :key="item.id">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <mt-switch></mt-switch>
          <img src="https://img.alicdn.com/bao/uploaded/i5/TB1drQTq.Y1gK0jSZFCtHgwqXXa_033840.jpg" />
          <div class="info">
            <h1>{{item.title}}</h1>
            <p>
              <span class="price">${{item.price}}</span>
              <numbox :inicount="$store.getters.getGoodsCount[item.id]" :goodsid="item.id"></numbox>
              <a href="#">删除</a>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import numbox from "../subcomponents/shopcar_numbox.vue";
export default {
  data() {
    return {
      goodslist: []
    };
  },
  created() {
    this.getGoodsList();
    console.log(this.$store.getters.getGoodsCount);
  },
  methods: {
    getGoodsList() {
    //   var idArr = [];
    //   this.$store.state.car.forEach(item => idArr.puch(item.id));
    //   if (idArr.length <= 0) {
    //     return;
    //   }
    //   this.$http
    //     .get("api/goods/getshopcarlist/" + idArr.join(","))
    //     .then(result => {
    //       if (result.body.status === 0) {
    //         this.goodslist = result.body.message;
    //       }
    //     });
    //-------------------------------------------------------------------------------
    // if(this.$store.state.car!="[]"){
    //     this.$store.state.car.forEach(item=>{
    //             this.goodslist.push({
    //                 cou:1,
    //                 id:item.id,
    //                 title:"title",
    //                 price:200,
    //                 src:"https://img.alicdn.com/bao/uploaded/i5/TB1drQTq.Y1gK0jSZFCtHgwqXXa_033840.jpg"
    //          })
    //     })
    // }
    
    this.goodslist=[
        {
            cou:1,
            id:1,
            title:"title",
            price:200,
            src:"https://img.alicdn.com/bao/uploaded/i5/TB1drQTq.Y1gK0jSZFCtHgwqXXa_033840.jpg"
        },
            {
            cou:1,
            id:2,
            title:"title",
            price:200,
            src:"https://img.alicdn.com/bao/uploaded/i5/TB1drQTq.Y1gK0jSZFCtHgwqXXa_033840.jpg"
        },
            {
            cou:1,
            id:3,
            title:"title",
            price:200,
            src:"https://img.alicdn.com/bao/uploaded/i5/TB1drQTq.Y1gK0jSZFCtHgwqXXa_033840.jpg"
        }
    ]
    }
  },
  components: {
    numbox
  }
};
</script>

<style lang="scss" scoped>
.shopcar-container {
  background-color: #eee;
  overflow: hidden;
  .goods-list {
    .mui-card-content-inner {
      display: flex;
      align-items: center;
    }
    img {
      width: 60px;
      height: 60px;
    }
    h1 {
      font-size: 13px;
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}
</style>